#!/usr/bin/python
# -*- coding:utf-8 -*-
#script name:fileDialog
import maya.cmds as mc
import mayaPrint
class FDialog(mayaPrint.MayaPrint ):
    def fileDialog(self,**flags):
        """
        m(fileMode) int: 
            0 for read 
            1 for write 
            2 for write without paths (segmented files) 
            4 for directories have meaning when used with the action 
            +100 for returning short names 
            
        """
        defineFlags = {"m":(0,int),"wt":('',str,u'',unicode),"ft":('',str,u'',unicode)}#"fileName":("",str,u'',unicode)}
        flagDirect = self.funtionFlag(defineFlags,**flags)
        ##read from flagDirect
        self.path=[]
        m = flagDirect["m"]
        ft = flagDirect["ft"]
        #--------------------
        mayaVersion = mc.about(f=True)
        res = []
        if mayaVersion<="2010":
            if m<=1:
                path = mc.fileDialog(m=m,directoryMask=ft)
                if path!="":
                    res = [path]
                elif path=="":
                    return None
            else:
                mc.fileBrowserDialog( m=m, fc=self.returnPath, an='ZCH', om='Import' )
                res = self.path
        else:
            #make 2001 same like 2008
            mapToOld = {0:1,1:0,4:3}
            m = mapToOld[m]
            path = mc.fileDialog2(fileMode=m, dialogStyle=2)
            if path!=None:
                res = path
        return res
        
    def returnPath(self,fileName, fileType):
        "For fileBrowserDialog"
        self.path.append(fileName)

